package com.mall.goods.controller;

import com.mall.entity.Result;
import com.mall.entity.StatusCode;
import com.mall.goods.service.SpuService;
import com.mall.pojo.Spu;
import com.mall.vo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author: bamboo on 20/7/12
 * @description: _标准产品单位
 */
@RestController
@RequestMapping("/spu")
@CrossOrigin
public class SpuController {
    @Autowired
    SpuService spuService;

    @PostMapping
    public Result add(@RequestBody Goods goods) {
        //    新增商品
        spuService.add(goods);
        return new Result(true, StatusCode.OK, "添加商品成功");
    }

    //     更新状态用putmapping
    @PutMapping("audit/{id}")
    public Result audit(@PathVariable String id, String status) {
        spuService.audit(id, status);
        return new Result();
    }

    //        下架商品
    @PutMapping("pull/{id}")
    public Result pull(String id) {
        spuService.pull(id);
        return new Result();
    }

    //    上架商品
    @PutMapping("put/{id}")
    public Result put(String id) {
        spuService.put(id);
        return new Result();
    }

    //    批量上架
    @PutMapping("putMany")
    private Result putMany(@RequestBody String[] ids) {

//        这里是说上架多少个
        int count = spuService.putMany(ids);
        return new Result(true, StatusCode.OK, "上架" + count + "个");
    }

    //    批量下架
    @PutMapping("soldOutBatch")
    private Result soldOutBatch(@RequestBody String[] ids) {
        int count = spuService.spuService(ids);
        return new Result(true, StatusCode.OK, "下架" + count + "个");

    }

}
